package cn.zzm.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.jms.connection.CachingConnectionFactory;

/**
 * @program: study
 * @description:springboot自动装配JMS的写法
 * @author: 周昭名
 * @create: 2019-04-11 14:54
 **/
@Configuration
public class ActiveMqConfig {

    /**
     * topic的发送JmsListenerContainerFactory
     * @param cachingJmsConnectionFactory
     * @return
     */
    @Bean("jmsTopicListenerContainerFactory")
    public JmsListenerContainerFactory jmsTopicListenerContainerFactory(@Autowired CachingConnectionFactory cachingJmsConnectionFactory) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(cachingJmsConnectionFactory);
        factory.setPubSubDomain(true);
        return factory;
    }
}

